/*
 * @Author: 毕晨曦
 * @Date: 2024-07-28 20:20:58
 * @LastEditors: 毕晨曦
 * @LastEditTime: 2024-07-28 22:31:34
 * @FilePath: /xing-fu-da-zi-weapp/src/api/im.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import fly from "@/utils/http";
const BASE_URL = "/im";
const BASE_URL_MESSAGE = "/im/message/private";
const userInfo = uni.getStorageSync("userInfo");

// 发送消息
export function sendMeessage(data: {
  recvId: string;
  content: string;
  type: string;
}) {
  return fly.post(`${BASE_URL_MESSAGE}/send`, data, {
    headers: {
      nid: userInfo.nid,
    },
  });
}

// 拉取离线消息
export function getOfflineMessage(minId: number) {
  return fly.get(
    `${BASE_URL_MESSAGE}/pullOfflineMessage`,
    {
      minId: minId,
    },
    {
      headers: {
        nid: userInfo.nid,
      },
    }
  );
}

// 拉取离线消息,消息将通过webscoket异步推送
export function getOfflineGroupMessage(minId: number) {
  return fly.get(
    `${BASE_URL}/message/group/pullOfflineMessage`,
    {
      minId: minId,
    },
    {
      headers: {
        nid: userInfo.nid,
      },
    }
  );
}
